# -*- coding: UTF-8 -*-
'''
Created on 16/10/2014

@author: Eduardo Cardeira - Num 6033

Exemplo 10 da Aula Teorica 4

'''
import sqlite3
conexao = sqlite3.connect('teste.db')
c = conexao.cursor()
c.execute('DROP TABLE IF EXISTS disc')
c.execute('CREATE TABLE disc (nome text, nota number)')
conexao.commit()
notas = [('P1', 15), ('P2', 15), ('LP', 19)]
c.executemany('INSERT INTO disc VALUES (?, ?)', notas)
conexao.commit()
c.execute("SELECT * FROM disc WHERE nota > 16")
print "uma... ", c.fetchone()
k = 0; soma = 0.0
for linha in c.execute("SELECT * FROM disc"):
    print linha; soma += linha[1]; k += 1
print "media = {:2.2f}".format(soma/k)
conexao.close()
